import 'package:logger/logger.dart';

import '../common/common_util.dart';

/// 日志工具类
class LogUtil {
  static final LogUtil _instance = LogUtil._internal();
  static var _logable = CommonUtil.debug;
  // static var _logable = true;

  // 私有的命名构造函数
  LogUtil._internal() {
    initLog();
  }
  static final logger = Logger(printer: PrettyPrinter(methodCount: 3));

  // 提供了一个工厂方法来获取该类的实例
  factory LogUtil() {
    return _instance;
  }

  initLog() {}

  void setLogable(bool logable) {
    _logable = logable;
  }

  d(String strLog) {
    if (_logable) {
      logger.d(strLog);
    }
  }

  i(String strLog) {
    if (_logable) {
      logger.i(strLog);
    }
  }

  w(String strLog) {
    if (_logable) {
      logger.w(strLog);
    }
  }

  e(String strLog) {
    if (_logable) {
      logger.e(strLog);
    }
  }
}
